#pragma once
#include "Primitive.h"

class CTriangle : public CPrimitive
{

private:
	CVector			*m_A;
	CVector			*m_B;
	CVector			*m_C;
	CVector			*m_NormalVector;

public:
	// Constructors & destructor
	CTriangle(void) : m_A(new CVector(-1.0f, 0.0f, 0.0f)), 
					  m_B(new CVector(1.0f, 0.0f, 0.0f)),
					  m_C(new CVector(0.0f, 1.0f, 0.0f)),
					  m_NormalVector(new CVector(0.0f, 0.0f, -1.0f)) { m_IsMesh = false; }
	CTriangle(CVector _a, CVector _b, CVector _c) : m_A(new CVector(_a)), m_B(new CVector(_b)), m_C(new CVector(_c)) { ComputeNormal(); m_IsMesh = false; }
	CTriangle(CVector _a, CVector _b, CVector _c, CLightIntensity _col) : m_A(new CVector(_a)), m_B(new CVector(_b)), m_C(new CVector(_c)) { m_Color = new CLightIntensity(_col); ComputeNormal(); m_IsMesh = false; }
	CTriangle(CVector _a, CVector _b, CVector _c, CVector _n, CLightIntensity _col) : m_A(new CVector(_a)), m_B(new CVector(_b)), m_C(new CVector(_c)), m_NormalVector((new CVector(_n))) { m_Color = new CLightIntensity(_col); m_IsMesh = false; }
    ~CTriangle();

	// Methods
	int			Intersect(CRay&, IsectData &);
	CVector		*GetA() { return m_A; }
	CVector		*GetB() { return m_B; }
	CVector		*GetC() { return m_C; }
	CVector		*GetNormalVector() { return m_NormalVector; };
	void		SetA(CVector _vec) { m_A = new CVector(_vec); }
	void		SetB(CVector _vec) { m_B = new CVector(_vec); }
	void		SetC(CVector _vec) { m_C = new CVector(_vec); }
	void		SetNormal(CVector _vec) { m_NormalVector = new CVector(_vec); }
	void		CheckNormal() { ComputeNormal(); }

private:
	float		GetParametricT(CRay&);
	void		ComputeNormal();
};
